package com.atguigu.lease.web.admin.config;

import com.atguigu.lease.common.converter.StringToBaseEnumConverterFactory;
import com.atguigu.lease.common.converter.StringToItemTypeConverter;
import com.atguigu.lease.web.admin.interceptor.AuthenticationInterceptor;
import com.atguigu.lease.web.admin.properties.AuthPathProperties;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.SpringBootConfiguration;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Configuration;
import org.springframework.format.FormatterRegistry;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

import javax.xml.validation.Validator;

@SpringBootConfiguration
@EnableConfigurationProperties(value= AuthPathProperties.class)
public class WebAdminMvcConfig implements WebMvcConfigurer {
    //    @Autowired
//    private StringToItemTypeConverter stringToItemTypeConverter;
    @Autowired
    private StringToBaseEnumConverterFactory stringToBaseEnumConverterFactory;
    @Autowired
    private AuthenticationInterceptor authenticationInterceptor;

    @Autowired
    private AuthPathProperties authPathProperties;

    @Override
    public void addFormatters(FormatterRegistry registry) {

//        registry.addConverter(stringToItemTypeConverter);
        registry.addConverterFactory(stringToBaseEnumConverterFactory);
    }

    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        registry.addInterceptor(authenticationInterceptor)
                .addPathPatterns(authPathProperties.getInclude())//拦截路径
                .excludePathPatterns(authPathProperties.getExclude());//排除路径
    }
}
